
    <!DOCTYPE html>
    <html lang="zh-CN">
    <head>
      <meta charset="UTF-8">
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      <title>hashMap1.7和1.8的区别 - 学习卡片</title>
      <style>
        body { font-family: sans-serif; background-color: #f0f8ff; color: #333; display: flex; flex-direction: column; align-items: center; padding: 50px 20px; }
        .header h1 { font-size: 32px; }
        .grid-container { display: grid; grid-template-columns: repeat(3, 1fr); gap: 28px; width: 100%; max-width: 1200px; }
        .card-container { perspective: 1200px; cursor: pointer; height: 250px; }
        .card { width: 100%; height: 100%; position: relative; transform-style: preserve-3d; transition: transform 0.7s; border-radius: 16px; box-shadow: 0 4px 16px rgba(0,0,0,0.08); }
        .card-container.flipped .card { transform: rotateY(180deg); }
        .card-face { position: absolute; width: 100%; height: 100%; backface-visibility: hidden; display: flex; flex-direction: column; box-sizing: border-box; border-radius: 16px; background-color: #fff; padding: 24px; }
        .card-back { background-color: #f0fff4; transform: rotateY(180deg); justify-content: space-between; }
        .card-category { font-size: 14px; color: #0052d9; margin-bottom: 8px; font-weight: 500; }
        .card-question { font-size: 20px; font-weight: 500; flex-grow: 1; display: flex; align-items: center; justify-content: center; text-align: center; }
        .card-answer-wrapper { flex-grow: 1; overflow-y: auto; }
        .card-answer { font-size: 15px; line-height: 1.7; }
        .card-footer { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 16px; margin-top: 16px; }
        .card-source { font-size: 13px; color: #8a919f; border-top: 1px solid #f0f0f0; padding-top: 12px; margin-top: 12px; }
      </style>
    </head>
    <body>
      <div class="header">
        <h1>hashMap1.7和1.8的区别 - 学习卡片</h1>
      </div>
      <div class="grid-container">
        
    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Java 1.8 `HashMap`在解决哈希冲突的机制上，与Java 1.7相比有哪些核心变化？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在Java 1.7中，`HashMap`仅使用链表来解决哈希冲突。从Java 1.8开始，`HashMap`引入了优化机制：当桶中的链表长度超过特定阈值（默认为8）时，该链表会被转换为红黑树，以提供更高效的查找性能。</div>
          </div>
          <div class="card-source">来源: 1. 冲突解决机制</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">理论</div>
          <div class="card-question">为什么在`HashMap`中，将长链表转换为红黑树可以提升查询效率？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">理论</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">因为链表的查找性能在最坏情况下为O(n)，而红黑树作为一种自平衡二叉搜索树，其查找性能可以稳定在O(log n)，在高冲突导致链表过长的情况下，性能优势明显。</div>
          </div>
          <div class="card-source">来源: 4. 内存结构和存储</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">技术</div>
          <div class="card-question">Java 1.8版本的`HashMap`是如何优化其散列算法以减少哈希冲突的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">技术</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Java 1.8的`HashMap`引入了更复杂的扰动算法。具体来说，它会使用键的`HashCode`的高位和低位进行扰动处理，这样做可以减少哈希冲突的可能性，从而提高整体性能。</div>
          </div>
          <div class="card-source">来源: 3. 性能优化</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">`ConcurrentHashMap`的并发控制机制从Java 1.7到Java 1.8发生了什么根本性的变化？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">Java 1.7的`ConcurrentHashMap`使用分段锁机制来提高并发性。而从Java 1.8开始，它摒弃了分段锁，转而采用更细粒度的锁和CAS（Compare-And-Swap）操作来实现更高的并发性能。</div>
          </div>
          <div class="card-source">来源: 7. ConcurrentHashMap 的变化</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">特性</div>
          <div class="card-question">`HashMap`迭代器的“快速失败”（fail-fast）特性是什么？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">特性</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">“快速失败”是指在使用迭代器遍历`HashMap`的过程中，如果`HashMap`的结构被外部修改（即非通过迭代器自身的remove方法），迭代器会立即抛出`ConcurrentModificationException`异常，以防止在不一致的状态下继续操作。</div>
          </div>
          <div class="card-source">来源: 5. 迭代器和快速失败</div>
        </div>
      </div>
    </div>

    <div class="card-container" onclick="this.classList.toggle('flipped');">
      <div class="card">
        <div class="card-face card-front">
          <div class="card-category">机制</div>
          <div class="card-question">Java 1.7中`HashMap`的扩容机制是如何工作的？</div>
          <div class="card-footer">点击卡片查看答案</div>
        </div>
        <div class="card-face card-back">
          <div class="card-category">机制</div>
          <div class="card-answer-wrapper">
            <div class="card-answer">在Java 1.7中，当`HashMap`进行扩容时，它会创建一个容量为原容量两倍的新数组，然后将所有旧的键值对重新计算哈希值，并迁移到新数组的对应桶中。这是一个时间复杂度为O(n)的操作。</div>
          </div>
          <div class="card-source">来源: 2. 扩容机制</div>
        </div>
      </div>
    </div>

      </div>
    </body>
    </html>
